| Conditions | 17 |
| Paths | 145 |
| Total Lines | 152 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like map.3d.weather.js ➔ ... ➔ $.getJSON often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /** |
||
| 30 | $.getJSON('/weather-json.php?latitude='+Cesium.Math.toDegrees(cposition.latitude)+'&longitude='+Cesium.Math.toDegrees(cposition.longitude),function(data) { |
||
| 31 | //delete_clouds(); |
||
| 32 | var coord = A.EclCoord.fromWgs84(Cesium.Math.toDegrees(cposition.latitude),Cesium.Math.toDegrees(cposition.longitude),0); |
||
| 33 | var tp = A.Solar.topocentricPosition(new A.JulianDay(new Date(viewer.clock.currentTime.toString())),coord,true); |
||
| 34 | var tpn = A.Solar.topocentricPosition(new A.JulianDay(new Date(Cesium.JulianDate.addSeconds(viewer.clock.currentTime,60,new Cesium.JulianDate()).toString())),coord,true); |
||
| 35 | //console.log(tp.hz); |
||
| 36 | //console.log(tpn.hz); |
||
| 37 | var ctime = Cesium.JulianDate.toGregorianDate(viewer.clock.currentTime); |
||
| 38 | var chour = ctime['hour']; |
||
| 39 | var cminute = ctime['minute']; |
||
| 40 | var datasource = new Cesium.CustomDataSource('clouds'); |
||
| 41 | var clouds = {ci: ['cirrocumulus1.glb','cirrocumulus2.glb','cirrocumulus3.glb','cirrocumulus4.glb','cirrocumulus5.glb','cirrocumulus6.glb','cirrocumulus7.glb','cirrocumulus8.glb','cirrocumulus9.glb']}; |
||
| 42 | //ac: ['altocumulus1.glb','altocumulus2.glb','altocumulus3.glb','altocumulus4.glb','altocumulus5.glb','altocumulus6.glb'], |
||
| 43 | //ns: ['nimbus1.glb','nimbus_sl1.glb','nimbus_sl2.glb','nimbus_sl3.glb','nimbus_sl4.glb','nimbus_sl5.glb','nimbus_sl6.glb']}; |
||
| 44 | //st: ['stratus1.glb','stratus2.glb','stratus3.glb','stratus4.glb','stratus5.glb']}; |
||
| 45 | // st need to follow camera |
||
| 46 | var cloudsb = {ac: ['altocumulus1.png','altocumulus2.png','altocumulus3.png','altocumulus4.png','altocumulus5.png','altocumulus6.png','altocumulus7.png','altocumulus8.png','altocumulus9.png'], |
||
| 47 | st: ['stratus1.png','stratus2.png','stratus3.png','stratus4.png','stratus5.png','stratus6.png'], |
||
| 48 | sc: ['congestus1.png','congestus2.png','congestus3.png'], |
||
| 49 | cu: ['cumulus1.png','cumulus2.png','cumulus3.png','cumulus4.png','cumulus5.png','cumulus6.png','cumulus7.png','cumulus8.png','cumulus9.png']}; |
||
| 50 | for (var i = 0; i < data.length; i++) { |
||
| 51 | var height = data[i]['alt']; |
||
| 52 | var cov = data[i]['cov']; |
||
| 53 | var cloud = clouds[data[i]['type']]; |
||
| 54 | //var cloud = clouds['ci']; |
||
| 55 | //var cloudb = cloudsb['fg']; |
||
| 56 | var cloudb = cloudsb[data[i]['type']]; |
||
| 57 | var rh = data[i]['rh']; |
||
| 58 | /* |
||
| 59 | var timecolors = [[100,100,100],[255,150,100],[255,255,255],[255,255,255],[255,255,255],[255,255,255],[255,150,100],[100,100,100],[100,100,100],[100,100,100],[100,100,100]]; |
||
| 60 | var timecolorsstep = chour/24*10; |
||
| 61 | if (Math.round(timecolorsstep) > Math.ceil(timecolorsstep)) { |
||
| 62 | console.log(Math.ceil(timecolorsstep)); |
||
| 63 | var prevcolor = timecolors[Math.ceil(timecolorsstep)]; |
||
| 64 | var nextcolor = timecolors[Math.round(timecolorsstep)]; |
||
| 65 | } else { |
||
| 66 | if (Math.round(timecolorsstep) == 0) { |
||
| 67 | var prevcolor = timecolors[0]; |
||
| 68 | } else { |
||
| 69 | var prevcolor = timecolors[Math.round(timecolorsstep)-1]; |
||
| 70 | } |
||
| 71 | var nextcolor = timecolors[Math.round(timecolorsstep)]; |
||
| 72 | } |
||
| 73 | var currentcolor = getColor(prevcolor,nextcolor,3*60,(timecolorsstep%3)*60+cminute); |
||
| 74 | var color = new Cesium.Color.multiply(new Cesium.Color(rh/100,rh/100,rh/100,1),new Cesium.Color.fromBytes(currentcolor['r'],currentcolor['v'],currentcolor['b'],255), new Cesium.Color()); |
||
| 75 | */ |
||
| 76 | //var color = new Cesium.Color(rh/100,rh/100,rh/100,1); |
||
| 77 | |||
| 78 | // 17:17 => az : 1.008 - alt : -0.021 |
||
| 79 | |||
| 80 | var prevcolor = [255,255,255]; |
||
|
|
|||
| 81 | if (tp.hz.alt < 0) { |
||
| 82 | prevcolor = [100,100,100]; |
||
| 83 | } else if (tp.hz.alt < 0.172) { |
||
| 84 | prevcolor = [255,150,100]; |
||
| 85 | } else if (tp.hz.alt < Math.PI/2) { |
||
| 86 | prevcolor = [255,255,255]; |
||
| 87 | } else if (tp.hz.alt < 2.9) { |
||
| 88 | prevcolor = [255,255,255]; |
||
| 89 | } else if (tp.hz.alt < 3.0) { |
||
| 90 | prevcolor = [255,150,100]; |
||
| 91 | } else { |
||
| 92 | prevcolor = [100,100,100]; |
||
| 93 | } |
||
| 94 | var nextcolor = [255,255,255]; |
||
| 95 | if (tpn.hz.alt < 0) { |
||
| 96 | nextcolor = [100,100,100]; |
||
| 97 | } else if (tpn.hz.alt < 0.172) { |
||
| 98 | nextcolor = [255,150,100]; |
||
| 99 | } else if (tpn.hz.alt < Math.PI/2) { |
||
| 100 | nextcolor = [255,255,255]; |
||
| 101 | } else if (tpn.hz.alt < 2.9) { |
||
| 102 | nextcolor = [255,255,255]; |
||
| 103 | } else if (tpn.hz.alt < 3.0) { |
||
| 104 | nextcolor = [255,150,100]; |
||
| 105 | } else { |
||
| 106 | nextcolor = [100,100,100]; |
||
| 107 | } |
||
| 108 | var timecolorsstep = chour/24*10; |
||
| 109 | var currentcolor = getColor(prevcolor,nextcolor,3*60,(timecolorsstep%3)*60+cminute); |
||
| 110 | var color = new Cesium.Color.multiply(new Cesium.Color(rh/100,rh/100,rh/100,1),new Cesium.Color.fromBytes(currentcolor['r'],currentcolor['v'],currentcolor['b'],255), new Cesium.Color()); |
||
| 111 | |||
| 112 | if (typeof cloudb != 'undefined') { |
||
| 113 | for (j = 0; j < 2000*cov; j++) { |
||
| 114 | var cloudcoord = generateRandomPoint(Cesium.Math.toDegrees(cposition.latitude),Cesium.Math.toDegrees(cposition.longitude), height,240,70000); |
||
| 115 | var position = Cesium.Cartesian3.fromDegrees(cloudcoord['longitude'],cloudcoord['latitude'],cloudcoord['alt']); |
||
| 116 | var heading = Cesium.Math.toRadians(135); |
||
| 117 | var pitch = 0; |
||
| 118 | var roll = 0; |
||
| 119 | var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); |
||
| 120 | var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); |
||
| 121 | var urlb = '/images/weather/clouds/'+cloudb[Math.floor((Math.random() * cloudb.length))]; |
||
| 122 | var entity = datasource.entities.add({ |
||
| 123 | name : url, |
||
| 124 | position : position, |
||
| 125 | orientation : orientation, |
||
| 126 | billboard: { |
||
| 127 | image : urlb, |
||
| 128 | sizeInMeters: true, |
||
| 129 | scale: Math.random()*10.0, |
||
| 130 | horizontalOrigin: Cesium.HorizontalOrigin.CENTER, |
||
| 131 | verticalOrigin: Cesium.VerticalOrigin.BOTTOM, |
||
| 132 | eyeOffset: new Cesium.Cartesian3(0,6,0), |
||
| 133 | heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, |
||
| 134 | //fillColor: Cesium.Color.fromCssColorString("#ffc107"), |
||
| 135 | //translucencyByDistance: new Cesium.NearFarScalar(200,.8,5E4,.2) |
||
| 136 | distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0,70000.0), |
||
| 137 | translucencyByDistance: new Cesium.NearFarScalar(1E5/2,.9,1E5,.3), |
||
| 138 | color: color, |
||
| 139 | opacity: .9 |
||
| 140 | } |
||
| 141 | }); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | //console.log(data[i]); |
||
| 145 | //console.log(cloud); |
||
| 146 | if (typeof cloud != 'undefined') { |
||
| 147 | //console.log('models'); |
||
| 148 | for (j = 0; j < 1000*cov; j++) { |
||
| 149 | var cloudcoord = generateRandomPoint(Cesium.Math.toDegrees(cposition.latitude),Cesium.Math.toDegrees(cposition.longitude), height,240,70000); |
||
| 150 | //console.log(cloudcoord); |
||
| 151 | var position = Cesium.Cartesian3.fromDegrees(cloudcoord['longitude'],cloudcoord['latitude'],cloudcoord['alt']); |
||
| 152 | if (data[i]['type'] == 'st') { |
||
| 153 | var heading = camera.heading; |
||
| 154 | } else { |
||
| 155 | var heading = Cesium.Math.toRadians(135); |
||
| 156 | } |
||
| 157 | var pitch = 0; |
||
| 158 | var roll = 0; |
||
| 159 | var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); |
||
| 160 | var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); |
||
| 161 | var url = '/models/gltf2/weather/'+cloud[Math.floor((Math.random() * cloud.length))]; |
||
| 162 | var entity = datasource.entities.add({ |
||
| 163 | name : url, |
||
| 164 | position : position, |
||
| 165 | orientation : orientation, |
||
| 166 | model : { |
||
| 167 | uri : url, |
||
| 168 | minimumPixelSize : 1, |
||
| 169 | maximumScale : 20000, |
||
| 170 | heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, |
||
| 171 | color: color, |
||
| 172 | colorBlendMode: Cesium.ColorBlendMode.MIX, |
||
| 173 | distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0,70000.0), |
||
| 174 | allowPicking: false |
||
| 175 | } |
||
| 176 | }); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
||
| 180 | viewer.dataSources.add(datasource); |
||
| 181 | }); |
||
| 182 | } |
||
| 239 | } |